package com.numberone.web.controller.coupon;

import com.numberone.framework.web.base.BaseController;
import com.numberone.system.domain.Coupon;
import com.numberone.system.domain.Goods;
import com.numberone.system.service.ICouponService;
import com.numberone.system.service.IGoodsService;
import com.numberone.system.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * 优惠券 信息操作处理
 *
 * @author 郭财源
 * @date 2020-10-09
 */
@Controller
@RequestMapping("/api/coupon")
public class CouponApiController extends BaseController {
    @Autowired
    private ICouponService couponService;
    @Autowired
    private IGoodsService goodsService;

    /**
     * 获取对应商品的优惠券
     * @param goodId
     * @return
     */
    @ResponseBody
    @PostMapping("/getCoupon")
    public Object getCoupon(Long goodId)
    {
        Goods goods = goodsService.selectGoodsById(goodId);
        Coupon coupon = new Coupon();
        coupon.setTypeId(goods.getTypethirdId());
        coupon.setStatus(1);
        coupon.setEndTime(new Date());
        List<Coupon> coupons = couponService.selectCouponList(coupon);
        return JsonResult.success(coupons);
    }
}
